﻿using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Abp.Domain.Values;
using JetBrains.Annotations;

namespace DHJ.Cost.CostBooking
{
    public class CostDetail : ValueObject<CostDetail>
    {
        public const int MaxCostCategoryLength = 20;
        public const int MaxCostTitleLength = 20;
        public const int MaxCostCodeLength = 20;

        [UsedImplicitly]
        private CostDetail()
        {
        }

        public CostDetail(string category, string title, string code, decimal amount)
        {
            Category = category;
            Title = title;
            Code = code;
            Amount = amount;
        }

        [Required]
        [MaxLength(MaxCostCategoryLength)]
        [Column(nameof(Category))]
        public string Category { get; private set; }

        [Required]
        [MaxLength(MaxCostTitleLength)]
        [Column(nameof(Title))]
        public string Title { get; private set; }

        [Required]
        [MaxLength(MaxCostCodeLength)]
        [Column(nameof(Code))]
        public string Code { get; private set; }

        [Column(nameof(Amount))]
        public decimal Amount { get; private set; }

        /// <summary>
        /// 根据比例返回成本金额的部分数值
        /// </summary>
        public CostDetail Portion(decimal ratio)
        {
            return new CostDetail(Category, Title, Code, Amount * ratio);
        }
    }
}